﻿using System;
using System.Collections.Generic;
using System.Text;
using HotelSoft.HotelManagement_BUS;
using System.Data;

namespace HotelSoft.HotelManagement_DAO
{
    class AccountDAO
    {
        public static DataTable SelectAll()
        {
            string sql = "SELECT * FROM ACCOUNT";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        public static bool CheckUsername(AccountDTO ACC)
        {
            string sql = "Select * From ACCOUNT where Username='" + ACC.USERNAME + "'";
            DataTable dt= Config.AccessHelper.ExecuteQuery(sql);
            if (dt.Rows.Count != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static bool Update(string Username, string Password)
        {
            try
            {
                string sql = "UPDATE ACCOUNT SET Password = '" + Password + "' where Username='" + Username + "'";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool Insert(AccountDTO ACC)
        {
            try
            {
                string sql = "Insert into ACCOUNT values ('" + ACC.USERNAME + "','" + ACC.PASSWORD + "','" + ACC.ROLE + "')";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool Delete(AccountDTO ACC)
        {
            try
            {
                string sql = "Delete From ACCOUNT Where Username='" + ACC.USERNAME + "'";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
